package cn.hsa.base.web.vo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * Table默认的分页参数创建
 * 
 * @author linxi
 * @date 2020年2月24日
 * @version 2020
 *
 * @param <T>
 */
public class PageFactory<T> {

    public static <T> Page<T> createPage(long pageNo, long pageSize) {
        return new Page<T>(pageNo, pageSize);
    }

    /**
     * com.github.pagehelper 辅助
     * 
     * @param list
     * @param page
     */
    public static <T> PageResultData<T> createPage(List<T> list, PageInfo<?> page) {
        PageResultData<T> result = new PageResultData<T>();
        result.setRows(list);
        result.setPageCount((long) page.getPages());
        result.setPageSize((long) page.getPageSize());
        result.setPageStart((long) page.getPageNum());
        result.setRowCount(page.getTotal());
        return result;
    }

    /**
     * com.baomidou.mybatisplus 辅助
     * 
     * @param list
     * @param page
     */
    public static <T> PageResultData<T> createPage(List<T> list, Page<?> page) {
        PageResultData<T> result = new PageResultData<T>();
        result.setRows(list);
        result.setPageCount((long) page.getPages());
        result.setPageSize((long) page.getSize());
        result.setPageStart((long) page.getCurrent());
        result.setRowCount(page.getTotal());
        return result;
    }
}
